from app import db
import datetime

#提取父类
class BaseModel(db.Model):
    #不生成表
    __abstract__=True
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    create_time = db.Column(db.DateTime,default=datetime.datetime.now())
    update_time = db.Column(db.DateTime,default=datetime.datetime.now())





# 管理员用户表
# id  name  mobile   roleid
class Intendant(BaseModel):
    __tablename__ = 'intendant'
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    name = db.Column(db.String(64),nullable=False)
    mobile = db.Column(db.String(32),nullable=False)
    roleid = db.Column(db.Integer,db.ForeignKey('role.id'),nullable=False)

# 角色表
# id  name
class Role(BaseModel):
    __tablename__ = 'role'
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    name = db.Column(db.String(64),nullable=False)

# 角色资源表
# roleid resid
Role_Resouce = db.Table('role_resouce',
                        db.Column('roleid',db.Integer,db.ForeignKey('role.id'),primary_key=True),
                        db.Column('resid',db.Integer,db.ForeignKey('resource.id'),primary_key=True)

)

# 资源表
# id name pid
class Resource(BaseModel):
    __tablename__ ='resource'
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    name = db.Column(db.String(64),nullable=False)
    pid = db.Column(db.Integer,db.ForeignKey('resource.id'),nullable=False,default=0)

# vip表
# id name 条件
class Vip(BaseModel):
    __tablename__ = 'vip'
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    name = db.Column(db.String(64),nullable=False)
    condition = db.Column(db.String(64),nullable=False)

from enum import Enum
class GenderEnum(Enum):
    MALE = '男'
    FEMALE = '女'


# 用户表
# id 用户名 手机号 余额 头像 vip等级 vipid 状态
class User(BaseModel):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    username = db.Column(db.String(64),nullable=False)
    mobile = db.Column(db.String(32),nullable=False)
    money = db.Column(db.Integer, default=0)
    url = db.Column(db.String(256),nullable=True)
    vip = db.Column(db.String(64),nullable=False)
    vipid = db.Column(db.Integer,db.ForeignKey('vip.id'),nullable=False,default=0)
    status = db.Column(db.Integer,default=0)
    sex = db.Column(db.Enum(GenderEnum),nullable=False)


# 用户信息表
# id userid 个性签名 身高 体重
class Userinfo(BaseModel):
    __tablename__ = 'userinfo'
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    userid = db.Column(db.Integer,db.ForeignKey('user.id'),nullable=False)
    signature = db.Column(db.String(256),nullable=True)
    height = db.Column(db.Integer)
    weight = db.Column(db.Integer)


# 标签表
# id name
class Tags(BaseModel):
    __tablename__ = 'tag'
    name = db.Column(db.String(64),nullable=False)


# 用户标签表
# userid tagid
user_tags = db.Table(
    'user_tags',
    db.Column('userid',db.Integer,db.ForeignKey('user.id'),primary_key=True),
    db.Column('tagid',db.Integer,db.ForeignKey('tag.id'),primary_key=True)
)
# 创建者表
# id money
class Creator(BaseModel):
    __tablename__ = 'creator'
    money = db.Column(db.Integer,nullable=False,default=0)



# 机构表
# 单位名称 创作级别
class Organization(BaseModel):
    __tablename__ = 'organization'
    name = db.Column(db.String(64),nullable=False)
    level = db.Column(db.Integer,nullable=False,default=0)

# 主播表
# id 总收益
class Anchor(BaseModel):
    __tablename__ = 'anchor'
    tmoney = db.Column(db.Integer,nullable=False,default=0)



# 充值记录表
class RechargeModel(BaseModel):
    __tablename__ = 'recharge'
    id = db.Column(db.Integer, primary_key=True, comment='订单ID')
    order = db.Column(db.String(20),comment="订单号")
    full = db.Column(db.String(20),comment="充值类型")
    money = db.Column(db.String(20),comment="充值金额")
    deal = db.Column(db.String(20),comment="交易状态")
    usernamne = db.Column(db.String(20),comment="用户名")
    url = db.Column(db.String(256),comment="头像")
    mobile = db.Column(db.String(11),comment="手机号")
    dealtime = db.Column(db.String(256),comment="交易时间")
    r_id = db.Column(db.Integer,db.ForeignKey('user.id'))



# 提现记录表 （充值50+50收益）
class Withdraw(BaseModel):
    id = db.Column(db.Integer, primary_key=True, comment='订单ID')
    order = db.Column(db.String(20), comment="订单号")
    money = db.Column(db.String(20), comment="提现金额")
    deal = db.Column(db.String(20), comment="交易状态")
    usernamne = db.Column(db.String(20), comment="用户名")
    url = db.Column(db.String(256), comment="头像")
    mobile = db.Column(db.String(11), comment="手机号")
    dealtime = db.Column(db.String(256), comment="交易时间")
    manager = db.Column(db.String(20),comment="审核管理员")
    w_id = db.Column(db.Integer,db.ForeignKey('user.id'))


# 抽成比例表
class Rak(BaseModel):
    __tablename__ = 'rak'
    rak = db.Column(db.DECIMAL(12,2))


# 提现设置
class Withdrawals(BaseModel):
    __tablename__ = 'withdrawals'
    max_money = db.Column(db.DECIMAL(12,2))
    count_money = db.Column(db.Integer,default=0)

# 频道表
class ChannelModel(BaseModel):
    __tablename__ = 'channel'
    id = db.Column(db.Integer, primary_key=True, comment='频道ID')
    name = db.Column(db.String(32), comment='频道名')
    visual = db.relationship("VisualModel", backref='channel')

# 工单分类表
class ClassifyModel(BaseModel):
    __tablename__ = 'classify'
    id = db.Column(db.Integer, primary_key=True, comment='ID')
    name = db.Column(db.String(20),comment="分类名称")



# 工单表
class WorkOrder(BaseModel):
    __tablename__ = 'workorder'
    id = db.Column(db.Integer, primary_key=True, comment='ID')
    userid = db.Column(db.String(20),comment="工单编号")
    username = db.Column(db.String(20),comment="用户名")
    mobile = db.Column(db.String(11),comment="手机号")
    lei = db.Column(db.String(20),comment="工单类别")
    report = db.Column(db.String(20),comment="举报")
    content = db.Column(db.String(20),comment="内容")
    url = db.Column(db.String(256),comment="图片")
    sponsor = db.Column(db.String(60),comment="发起时间")
    service = db.Column(db.String(20),comment="对接客服")
    state = db.Column(db.String(30),comment="处理状态")
    w_id = db.Column(db.Integer,db.ForeignKey('classify.id'))

# 通知告知表
class Inform(BaseModel):
    id = db.Column(db.Integer, primary_key=True, comment='ID')
    ID = db.Column(db.String(20),comment="通告ID")
    headline = db.Column(db.String(30),comment="标题")
    page = db.Column(db.String(40),comment="所属页面")
    issue = db.Column(db.String(60),comment="发布时间")
    state = db.Column(db.String(30),comment="状态")


#页面表
class Page(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(100))
    frequency = db.Column(db.Integer,default=0)
    ad_page = db.relationship('AdPage', backref='page')



# 广告设置表
class Ad(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(100))
    sort = db.Column(db.Integer,default=0)
    ad_page = db.relationship('AdPage',backref='ad')



# 广告页面表
class AdPage(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    ad_id=db.Column(db.Integer,db.ForeignKey('ad.id'))
    page_id=db.Column(db.Integer,db.ForeignKey('page.id'))

# 视频配置表
class Video(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    str=db.Column(db.String(100))



# 外链表
# id 名称 图片 地址 金额
class Link(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(100))
    icon=db.Column(db.String(100))
    url=db.Column(db.String(100))
    price=db.Column(db.Integer)
    link_record = db.relationship('LinkRecord', backref='link')


# 外链记录表
# id 来源
class LinkRecord(BaseModel):
    id=db.Column(db.Integer,primary_key=True)
    from_id=db.Column(db.Integer,db.ForeignKey('link.id'))
    amount=db.Column(db.Integer,default=0)

# 礼物表
class Gift(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(30))
    url = db.Column(db.String(255))
    price = db.Column(db.Integer)



# 体现设置表
class Order(BaseModel):
    once_money = db.Column(db.Integer)
    month_money = db.Column(db.Integer)

# 抽成比例表
class Rake(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    rake_name = db.Column(db.Integer)

# 视频分类表
class VisualModel(BaseModel):
    __tablename__ = 'visual'
    id = db.Column(db.Integer, primary_key=True, comment='频道ID')
    name = db.Column(db.String(32),comment='视频分类名称')
    pid = db.Column(db.Integer, db.ForeignKey("channel_model.id"))

# 公司表
class Player(BaseModel):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(30))
    url = db.Column(db.String(255))
    mobie = db.Column(db.String(11), unique=True)
    gender = db.Column(db.String)
    level = db.Column(db.Integer)
    long_video = db.Column(db.Integer)
    break_video = db.Column(db.Integer)

# 帖子分类表
class Classification(BaseModel):
    __tablename__ = 'classification'
    id = db.Column(db.Integer, primary_key=True, comment='帖子分类ID')
    name = db.Column(db.String(32),comment='分类名')
    invitation = db.relationship("InvitationModel",backref='classification')

# 帖子表
class InvitationModel(BaseModel):
    __tablename__ = 'invitation'
    id = db.Column(db.Integer, primary_key=True, comment='帖子ID')
    name = db.Column(db.String(32),comment='帖子名称')
    likes = db.Column(db.Integer,default=0,comment='点赞量')
    classification_id = db.Column(db.Integer,db.ForeignKey("classification_model.id"))

db.create_all()